package cn.xspace.wnx.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.xspace.android.xafcommon.view.RoundAngleImageView;

import java.util.List;

import cn.xspace.wnx.R;
import cn.xspace.library.bean.OrgDeptUserBean;
import com.xspace.android.xafcommon.util.HeadShowUtil;

public class HorizontalScrollViewAdapter {

    private Context mContext;
    private LayoutInflater mInflater;
    private List<OrgDeptUserBean> mDatas;
    IDeleteOne ideleteLisener;

    public interface IDeleteOne {
        void onDeleteOne(int pos);
    }

    public HorizontalScrollViewAdapter(Context context, List<OrgDeptUserBean> mDatas, IDeleteOne ideleteLisener) {
        this.mContext = context;
        mInflater = LayoutInflater.from(context);
        this.mDatas = mDatas;
        this.ideleteLisener = ideleteLisener;
    }


    public void setmDatas(List<OrgDeptUserBean> mDatas) {
        this.mDatas = mDatas;
    }

    public int getCount() {
        return mDatas.size();
    }

    public Object getItem(int position) {
        return mDatas.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        OrgDeptUserBean ufb = null;
        if (mDatas.size() > 0) {
            ufb = mDatas.get(position);
        }
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_select_memer_user, null);
            viewHolder.mImg = (RoundAngleImageView) convertView
                    .findViewById(R.id.img_head);
//            viewHolder.mdel = (ImageView) convertView
//                    .findViewById(R.id.img_head);
            viewHolder.mText = (TextView) convertView
                    .findViewById(R.id.txt_name);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (ufb != null) {
            viewHolder.mText.setText("" + ufb.user_name);
            HeadShowUtil.headShow(mContext, ufb.user_logo, ufb.user_sex, viewHolder.mImg,HeadShowUtil.HeadType.UserLogo);
//            if(!TextUtils.isEmpty(ufb.user_logo)){
//                Picasso.with(mContext)
//                        .load(ufb.user_logo)
//                        .placeholder(R.drawable.icon_header_default)
//                        .error(R.drawable.icon_header_default)
//                        .into(viewHolder.mImg);
//            }



//            viewHolder.mdel.setOnClickListener(new OnClickListener() {
//
//                @Override
//                public void onClick(View v) {
//                    if (ideleteLisener != null)
//                        ideleteLisener.onDeleteOne(position);
//                }
//            });
        }
        return convertView;
    }

    private class ViewHolder {
        ImageView mImg;
        TextView mText;
    }

}
